package com.nk.iexam;

import java.util.List;

import com.nk.iexam.adapter.CategoryAdapter;
import com.nk.iexam.ds.CategoryDataSource;
import com.nk.iexam.models.Category;
import com.nk.iexam.models.Subject;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;

public class SubjectActivity extends ListActivity
{
	public static final String TAG = "SubjectActivity";
	public static final String SUBJECT = "subject";
	private List<Category> _categories;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        Subject subject = (Subject) getIntent().getSerializableExtra(SUBJECT);
        CategoryDataSource categoryDataSource = new CategoryDataSource();
        _categories = categoryDataSource.selectObjects(CategoryDataSource.SUBJECT_ID + " = " + subject.getId());
                
        View header = (View)getLayoutInflater().inflate(R.layout.list_header, null);
        TextView headerTextView  = (TextView)header.findViewById(R.id.txtHeader);
        headerTextView.setText(getString(R.string.category_list_header) + " " + subject.getName());
        getListView().addHeaderView(header);
        
        setListAdapter(new CategoryAdapter(this, R.layout.list_row, _categories));
    }
    
    @Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Category category = _categories.get(position - 1);
		Intent intent = new Intent(this, ReviewActivity.class);
		intent.putExtra(ReviewActivity.CATEGORY, category);
		startActivity(intent);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //getMenuInflater().inflate(R.menu.activity_subject, menu);
        return true;
    }
}
